package com.ruoyi.project.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.TSubject;
import com.ruoyi.project.system.service.ITSubjectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 科目Controller
 * 
 * @author ruoyi
 * @date 2020-05-09
 */
@RestController
@RequestMapping("/system/subject")
public class TSubjectController extends BaseController
{
    @Autowired
    private ITSubjectService tSubjectService;

    /**
     * 查询科目列表
     */
    @PreAuthorize("@ss.hasPermi('system:subject:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSubject tSubject)
    {
        startPage();
        List<TSubject> list = tSubjectService.selectTSubjectList(tSubject);
        return getDataTable(list);
    }

    /**
     * 导出科目列表
     */
    @PreAuthorize("@ss.hasPermi('system:subject:export')")
    @Log(title = "科目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TSubject tSubject)
    {
        List<TSubject> list = tSubjectService.selectTSubjectList(tSubject);
        ExcelUtil<TSubject> util = new ExcelUtil<TSubject>(TSubject.class);
        return util.exportExcel(list, "subject");
    }

    /**
     * 获取科目详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:subject:query')")
    @GetMapping(value = "/{subjectId}")
    public AjaxResult getInfo(@PathVariable("subjectId") Integer subjectId)
    {
        return AjaxResult.success(tSubjectService.selectTSubjectById(subjectId));
    }

    /**
     * 新增科目
     */
    @PreAuthorize("@ss.hasPermi('system:subject:add')")
    @Log(title = "科目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSubject tSubject)
    {
        return toAjax(tSubjectService.insertTSubject(tSubject));
    }

    /**
     * 修改科目
     */
    @PreAuthorize("@ss.hasPermi('system:subject:edit')")
    @Log(title = "科目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSubject tSubject)
    {
        return toAjax(tSubjectService.updateTSubject(tSubject));
    }

    /**
     * 删除科目
     */
    @PreAuthorize("@ss.hasPermi('system:subject:remove')")
    @Log(title = "科目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subjectIds}")
    public AjaxResult remove(@PathVariable Integer[] subjectIds)
    {
        return toAjax(tSubjectService.deleteTSubjectByIds(subjectIds));
    }
}
